import express from 'express';
import { getConnection } from '../config/database.js';

const router = express.Router();

/**
 * 调试：查看数据库中的所有配置数据
 */
router.get('/config', async (req, res) => {
  try {
    const connection = await getConnection();
    if (!connection) {
      return res.json({
        success: false,
        error: '数据库未连接'
      });
    }

    const [rows] = await connection.execute(
      'SELECT config_key, config_value FROM app_config ORDER BY config_key'
    );

    res.json({
      success: true,
      data: {
        totalRows: (rows as any[]).length,
        rows: rows
      }
    });
  } catch (error) {
    console.error('调试查询失败:', error);
    res.status(500).json({
      success: false,
      error: error.message
    });
  }
});

export default router;